layui.use(['layer','table','jquery','form'],function(){
    let layer = layui.layer,
        table = layui.table,
        $ = layui.jquery,
        form = layui.form;

    //加载数据表格
    let tabInstance = table.render({
        elem: '#serviceList',
        url: '/service-management/findNewService', //数据接口
        page: true, //开启分页
        limit:5, //每页显示的条数，默认10
        limits:[5,10,15,20,], //每页显示条数选择框数据
        request:{
            pageName: 'current',
            limitName: 'size'
        },
        cols: [[ //表头
            {field: 'serviceId', title: '编号', width:80, sort: true, fixed: 'left'},
            {field: 'customerName', title: '客户名称'},
            {field: 'outline', title: '概要'},
            {field: 'serviceType', title: '服务类型'},
            {field: 'creationName', title: '创建人'},
            {field: 'creationTime', title: '创建时间'},
            {field: 'serviceReq', title: '服务请求'},
            {field: 'status', title: '状态'},
            {title: '操作', width: 100,fixed:'right',toolbar:"#userTool"}
        ]]
    });

    //搜索监听启用
    form.on('submit(search)',function(data){
        tabInstance.reload({
            where :data.field
        });
        return false;
    });

    //工具栏操作
    table.on('tool(serviceAllot)',function(obj){
    switch (obj.event){
        case 'allot_btn':
            //分配
            layer.open({
                title:"分配给",
                type:2,
                content:"views/service_management/allot.jsp",
                area:['400px','400px'],
                offset:'t',
                skin:"layui-layer-molv",
                btn:['确定','取消'],
                //弹出层成功后执行的回调函数
                success: function(layero, index){
                    let body = layer.getChildFrame("body",index);
                    body.find(".num").val(obj.data.serviceId);

                },
                yes: function(index, layero){
                    let body = layer.getChildFrame("body",index);
                    let data = {};
                    body.find("#allotForm").serializeArray().forEach(function(item){
                        data[item.name] = item.value;
                    });
                    $.post('service-user-allot/allotService',data,function(result){
                        layer.msg(result.msg);
                        setTimeout(function(){
                            layer.close(index);
                            parent.location.reload();
                        },300);
                    });
                }
            });
                break;
            // case 'del_btn':
            //     layer.confirm('你确定要删除编号【'+obj.data.serviceId+'】吗？',{icon:3,anim: 4,skin:'layui-layer-molv'},function(){
            //         $.post('service-user-allot/del/'+obj.data.id,function(data){
            //             tabInstance.reload();
            //             layer.msg(data.msg);
            //         });
            //     });
        }
    });

});

